package com.hnucm.javaweb;

import com.hnucm.javaweb.dao.UserDao;
import com.hnucm.javaweb.dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name="MyServlet",value = "/MyServlet")
public class Myservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//接收请求转发页面    面向接口编程，方便扩展
//        super.doGet(req, resp);
//        resp.getWriter().println("hello world");
        //要创建的类写到配置文件中，从配置文件中读取类名，然后反射动态地创建该对象
        UserDao userDao = new UserDaoImpl();
        req.setAttribute("name", userDao.getName());
        req.getRequestDispatcher("login.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
